package eu.reply.android.flashm;

import java.util.ArrayList;
import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;

public class ViewOnMap extends MapActivity {
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_on_map);  
        
        
        MapView mapView = (MapView) findViewById(R.id.mapview);
        List<Overlay> mapOverlays = mapView.getOverlays();
//        Drawable drawable = this.getResources().getDrawable(R.drawable.flashmob_on_beach);
        Drawable drawable = this.getResources().getDrawable(getIntent().getIntExtra(MainActivity.EXTRA_EVENT_IMAGE_ID,R.drawable.flashmob_on_beach));
        drawable.setBounds(-drawable.getIntrinsicWidth() / 5, -drawable.getIntrinsicHeight() / 2, drawable.getIntrinsicWidth() / 5, 0);
        
        GeoPoint loaction = new GeoPoint((int)(getIntent().getDoubleExtra(EventDetailsActivity.EXTRA_LOCATION_LATITUDE,0.0) * 1E6), (int)(getIntent().getDoubleExtra(EventDetailsActivity.EXTRA_LOCATION_LONGITUDE,0.0) * 1E6));
        
        FlashMapOverlay flashMapOverlay = new FlashMapOverlay(drawable, this);

        
        OverlayItem overlayitem = new OverlayItem(loaction, 
        		getIntent().getStringExtra(MainActivity.EXTRA_EVENT_NAME),
        		getIntent().getStringExtra(MainActivity.EXTRA_EVENT_DATE));
        flashMapOverlay.addOverlay(overlayitem);
        overlayitem.setMarker(drawable);
        mapOverlays.add(flashMapOverlay);
        
        MapController mapController = mapView.getController();
        mapController.setCenter(loaction);
        mapController.setZoom(15);
        mapView.setBuiltInZoomControls(true);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_view_on_map, menu);
        return true;
    }

    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

}
